package heapsort;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class Reader {

	private FileReader fr;
	private BufferedReader br;
	private ArrayList<String> line;
	private int teller;

	public Reader(String path) {
		try {
			fr = new FileReader(new File(path));
			br = new BufferedReader(fr);
			line = new ArrayList<String>();
			teller = 0;
			read();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void read() {
		try {
			String[] tmp = br.readLine().split(" ");
			for (String st : tmp) {
				line.add(st);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public boolean empty() {
		return line.isEmpty();
	}

	public int getOneInt() {
		int ret = -1;

		try {
			if (!this.empty()) {
				ret = Integer.parseInt(line.get(0));
				line.remove(0);
				teller++;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

		return ret;
	}

	public int getTeller() {
		return teller;
	}

	public void close() {
		try {
			br.close();
			fr.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
